#pragma once
#include "afn0dtypes.h"
#include <map>

#define Afn0dfx_Fx(AP,x)\
	AP##Afn0df##x& F##x(uint16_t)

#define int_parseFx(x)\
	int parseF##x(uint8_t*)

#define AFN0D_PARSER_DEFINITION(AP) \
class AP##Afn0dParser\
{\
public:\
	typedef AP##Afn0dTypes Union;\
	typedef map<uint8_t,map<uint16_t,Union>> UnionMap;\
	typedef int(AP##Afn0dParser::*Callback)(uint8_t*);\
	UnionMap umap;\
protected:\
	Callback call[256];\
public:\
	AP##Afn0dParser(void);\
public:\
	void clear(void);\
	void get(Mapmss&);\
	bool set(Mapmss& m);\
	bool append(Buffer&);\
public:\
	Afn0dfx_Fx(AP,1);\
	Afn0dfx_Fx(AP,2);\
	Afn0dfx_Fx(AP,3);\
	Afn0dfx_Fx(AP,4);\
	Afn0dfx_Fx(AP,5);\
	Afn0dfx_Fx(AP,6);\
	Afn0dfx_Fx(AP,7);\
	Afn0dfx_Fx(AP,8);\
public:\
	int parse(uint8_t *data, int len);\
	int_parseFx(1);\
	int_parseFx(2);\
	int_parseFx(3);\
	int_parseFx(4);\
	int_parseFx(5);\
	int_parseFx(6);\
	int_parseFx(7);\
	int_parseFx(8);\
};

#pragma pack(1)
AFN0D_PARSER_DEFINITION(Active)
AFN0D_PARSER_DEFINITION(Pasive)
#pragma pack(0)

class Afn0dParser
{
	ActiveAfn0dParser active;
	PasiveAfn0dParser pasive;
public:
	Afn0dParser(void);
};
